package com.jde.parent.result;

import lombok.Data;

/**
 * @description: 统一返回类 <br>
 * @date: 2019/8/29 10:37 <br>
 * @author: jiangde <br>
 * @version: 1.0 <br>
 */
@Data
public class ResultVO<T> {

    private int code;
    private String msg;
    private T datas;

    private ResultVO() {
    }

    private ResultVO(int code, String msg, T datas) {
        this.code = code;
        this.msg = msg;
        this.datas = datas;
    }

    private ResultVO(ResultInterface resultInterface) {
        this.code = resultInterface.code();
        this.msg = resultInterface.msg();
    }


    private ResultVO(ResultInterface resultInterface, T datas) {
        this.code = resultInterface.code();
        this.msg = resultInterface.msg();
        this.datas = datas;
    }


    public static <T> ResultVO<T> success(T data) {
        return new ResultVO<>(ResultEnum.SUCCESS, data);
    }

    public static <T> ResultVO<T> success() {
        return new ResultVO(ResultEnum.SUCCESS);
    }

    public static <T> ResultVO<T> exception(ResultInterface resultInterface) {
        return new ResultVO<>(resultInterface);
    }

    public static <T> ResultVO<T> exception(ResultInterface resultInterface, T datas) {
        return new ResultVO<>(resultInterface, datas);
    }


}
